"use server";
import { listQuestionBankVoByPageUsingPost } from "@/api/questionBankController";
import QuestionBankList from "@/components/QuestionBankList";
import { Flex } from "antd";
import Title from "antd/es/typography/Title";

export default async function Banks() {
  let bankPageParams = {
    current: 1,
    pageSize: 200, //题库数量不多，直接全量获取
    sortField: "createTime",
    sortOrder: "descend",
  };
  let bankList: API.QuestionBankVO[] = [];
  try {
    await listQuestionBankVoByPageUsingPost(bankPageParams).then((res) => {
      const { data } = res;
      bankList = (data as API.PageQuestionVO_)?.records ?? [];
    });
  } catch (error: any) {
    console.error("获取题库失败" + error.message);
  }
  return (
    <div id="banks">
      <Flex align="center" justify="space-between">
        <Title level={2}>最新题库</Title>
      </Flex>
      <div>
        <QuestionBankList questionBankList={bankList} />
      </div>
    </div>
  );
}
